package cn.wolfcode.lww.service.impl;

import cn.wolfcode.lww.domain.Strategy;
import cn.wolfcode.lww.mapper.StrategyMapper;
import cn.wolfcode.lww.service.StrategyService;
import cn.wolfcode.lww.util.QueryObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class StrategyServiceImpl implements StrategyService {
    @Autowired
    StrategyMapper strategyMapper;
    @Override
    public int deleteByPrimaryKey(String id) {
        int i = strategyMapper.deleteByPrimaryKey(id);
        return i;
    }

    @Override
    public int insert(Strategy record)
    {
        int insert = strategyMapper.insert(record);
        return insert;
    }

    @Override
    public PageInfo<Strategy> selectAll(QueryObject queryObject,String classfiy) {
        PageHelper.startPage(queryObject.getCurrentPage(),queryObject.getPageSize());
        List<Strategy> strategies = strategyMapper.selectAll(classfiy);

        return new PageInfo<Strategy>(strategies);
    }

    @Override
    public int updateByPrimaryKey(Strategy strategy)
    {
        strategyMapper.updateByPrimaryKey(strategy);
        return 0;
    }

    @Override
    public Strategy selectByPrimaryKey(String id){
        Strategy strategy = strategyMapper.selectByPrimaryKey(id);
        return strategy;
    };

    @Override
    public void updateWatchById(String id){
strategyMapper.updateWatchById(id);
    }

    @Override
    public PageInfo<Strategy> searchAllByTitle(QueryObject queryObject,String title) {
        List<Strategy> strategies = strategyMapper.searchAllByTitle(title);
        PageHelper.startPage(queryObject.getCurrentPage(),queryObject.getPageSize());
        return new PageInfo<Strategy>(strategies);
    }

    ;
}
